<?php

/**
 * URL管理类
 * 
 * @author keluo <pycorvn@yeah.net>
 * @since 2012-10-26 15:59:43
 */
class SCUrl {
	
	/**
	 * 项目web根目录
	 * @var string
	 */
	public $root;
	
	public function __construct() {
		$this->root = SCRequest::getBaseURI();
	}
	
	/**
	 * 生成完整路径URL
	 * @param string $route
	 * @param boolean $absolute 是否生成绝对路径
	 * @param string $space url中的空白部分被替代的字符串
	 * @return $url;
	 */
	public function create($route = '', $absolute = true, $space = '') {
		$baseUri = 'http://' . $_SERVER['HTTP_HOST'] . SCRequest::getBaseURI();
		$route = trim(trim($route), '/');
		if($space) {
			$route = preg_replace('/\s+/', $space, $route);
		}
		if($route == '') {
			return $baseUri;
		}
		
		if (!SCConfig::get('REWRITE')) {
			$baseUri .= '/'.SCConfig::getEntrance();
		}
		return $baseUri.'/'.$route.SCConfig::getUrlSuffix();
	}
	
}